package asia.lxq.cic.entity;

import asia.lxq.cic.dao.UserMapper;
import asia.lxq.cic.util.UserDirUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.File;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Comment {
    @TableId(value = "comment_id",type = IdType.AUTO)
    Integer commentId;
    int commentParentId;
    String commentContent;
    int  commentArticleId;
    Date commentDate;
    int commentUserId;
    int commentThumb;
    @TableField(exist = false)
    List<Comment> subComment;
    @TableField(exist = false)
    String userPicUrl;
    @TableField(exist = false)
    String userNickname;

    public void query(UserMapper userMapper){
//        System.out.println("commentParentId = "+commentParentId+" ; commentUserId = "+commentUserId+" ; commentId = "+commentId);
        User user = userMapper.selectById(commentUserId);
        userNickname=user.getNickname();
        String userPicFilePath = UserDirUtil.getRealUserPic(user.getUserId());
        File userPicFile=new File(userPicFilePath);
        if (userPicFile.exists())userPicUrl= UserDirUtil.getUserPic(user.getUserId());else userPicUrl=null;
        if (commentParentId==0){
            subComment.forEach(sub->sub.query(userMapper));
        }
    }
}
